<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="multipart/form-data">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>订单管理后台</title>
    <link rel="stylesheet" href="layui/css/layui.css">
    <link rel="stylesheet" href="css/pintuer.css">
    <link rel="stylesheet" href="css/admin.css">
    <script src="js/jquery.js"></script>
    <script src="layui/layui.js"></script>
    <script src="js/admin.js"></script>
</head>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo">皮皮虾小魔仙后台</div>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <img src="images/bid_new.gif" class="layui-nav-img">${name}
            </li>
            <li class="layui-nav-item"><a href="index.jsp" target="_top" id="out">退出</a></li>
        </ul>
    </div>

    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <ul class="layui-nav layui-nav-tree"  lay-filter="test">
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="javascript:;" >查看订单</a>
                    <dl class="layui-nav-child">
                        <dd><a onclick="allorders()">所有订单</a></dd>
                        <dd><a onclick="unisokorders()">未确认订单</a></dd>
                        <dd><a onclick="isokorders()">已确认订单</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item layui-nav-itemed">
                    <a href="javascript:;">商品查看</a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:;" onclick="goodshow(0)">所有商品</a></dd>
                        <dd><a href="javascript:;" onclick="goodshow(1)">美食</a></dd>
                        <dd><a href="javascript:;" onclick="goodshow(2)">饮品</a></dd>
                        <dd><a href="javascript:;" onclick="goodshow(3)">水果</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item"><a href="javascript:;" onclick="userset()">账户管理</a></li>
                <li class="layui-nav-item"><a href="admin_goods.jsp">发布商品</a></li>
            </ul>
        </div>
    </div>

    <div class="layui-body" id="main_are" style="text-align: center">
        <table class="table table-hover text-center" style="text-align: center;font-size: 15px" border="1" id="odertable">
            <tr>
                <th style="width: 50px">姓名</th>
                <th style="width: 80px">订单号</th>
                <th style="width: 250px">地址</th>
                <th style="width: 200px">电话</th>
                <th style="width: 50px">数量</th>
                <th style="width: 200px">下单时间</th>
                <th style="width: 80px">总价格</th>
                <th style="width: 80px">订单状态</th>
                <th style="width: 300px">操作</th>
            </tr>
            <c:forEach items="${orderList}" var="user">
                <form action="update_oder.do" method="post" id="up_oder_form_${user.order_id}">
                    <input type="hidden" value="${user.order_id}" name="order_id">
                    <input type="hidden" value="${user.order_num}" name="order_num">
                    <input type="hidden" value="${user.order_time}" name="order_time">
                    <tr style="text-align: center">
                        <c:if test="${user.isok==0}">
                            <td><input type="text" name="name" size="5" value="${user.name}" id="name_${user.order_id}" style="border: none;text-align: center"></td>
                            <td>${user.order_num}</td>
                            <td><input type="text" name="address"  size="40" value="${user.address}" id="address_${user.order_id}"  style="border: none;text-align: center"></td>
                            <td><input type="text" name="tel"  size="20" value="${user.tel}" id="tel_${user.order_id}" style="border: none;text-align: center"></td>
                            <td><input type="text" name="order_count" size="5" value="${user.order_count}" style="border: none;text-align: center"></td>
                            <td>${user.order_time}</td>
                            <td><input type="text" name="order_price" size="8" value="${user.order_price}" style="border: none;text-align: center"></td>
                            <td ><span style="color: red">未确认</span></td>
                            <td>
                                <button type="button" class="layui-btn"  onclick="ckeck_ok(${user.order_id})" id="ok_${user.order_id}">确认订单</button>
                                <button type="submit" class="layui-btn" onclick="up_order_form(${user.order_id})">修改</button>
<%--                                onclick="ckeck_updata(${user.order_id})" id="updata_${user.order_id}"--%>
                                <button type="button" class="layui-btn" style="color: red" onclick="ckeck_del(${user.order_id})" id="del_${user.order_id}">删除</button>
                            </td>
                        </c:if>
                        <c:if test="${user.isok==1}">
                            <td>${user.name}</td>
                            <td>${user.order_num}</td>
                            <td>${user.address}</td>
                            <td>${user.tel }</td>
                            <td>${user.order_count}</td>
                            <td>${user.order_time}</td>
                            <td>${user.order_price}</td>
                            <td>已确认</td>
                            <td>
                                <button type="button" class="layui-btn"  onclick="ckeck_updataend()" style="color: #0C0C0C">确认订单</button>
                                <button type="button" class="layui-btn"  onclick="ckeck_updataend()" style="color: #0C0C0C">修改</button>
                                <button type="button" class="layui-btn"  onclick="ckeck_updataend()" style="color: #0C0C0C">删除</button>
                            </td>
                        </c:if>
                    </tr>
                </form>
            </c:forEach>
        </table>
    </div>
    <div class="layui-footer">
        © 皮皮虾小魔仙外卖.com
    </div>
</div>
</body>
<script>
    var websocket=null;
    if('WebSocket' in window){
        websocket=new WebSocket('ws://localhost:8080<%=path%>/webSocket');
    }else{
        alert("该浏览器不支持websocket");
    }
    websocket.onopen=function (event) {
        console.log('建立链接');
    }
    websocket.onclose=function (event) {
        console.log('链接关闭');
    }
    websocket.onmessage=function (event) {
        console.log('收到消息'+event.data)
        //消息提醒
        layer.confirm("你有新的订单", {
                but: ['我看看', '懒得看'],}
            ,function () {
                $.ajax({
                    url: "unisokorders.do",
                    type: "POST",
                    success: function () {
                        window.location.href = "admin.jsp";
                    }
                })
            }
        );
    }
    websocket.onerror=function (event) {
        alert("发生错误");
    }
    window.onbeforeunload=function () {
        websocket.close();
    }
</script>
</html>

